<template>
  <div class="todo-footer" v-show="todos.length">
    <label>
      <input type="checkbox" v-model="allCheck" />
    </label>
    <span>
      <span>已完成{{ overNum }}</span> / 全部{{ todos.length }}
    </span>
    <button class="btn btn-danger" @click="deleteAllCheck">
      清除已完成任务
    </button>
  </div>
</template>

<script>
export default {
  name: "Footer",
  props: ["todos", "updateAllTodo", "deleteAll"],
  computed: {
    // 计算已完成数量
    overNum() {
      let num = 0;
      this.todos.forEach((item) => {
        if (item.isOver) {
          num++;
        }
      });
      return num;
    },
    // 全选全不选
    allCheck: {
      get() {
        return this.todos.every((item) => item.isOver);
      },
      set(newVal) {
        this.updateAllTodo(newVal);
      },
    },
  },
  methods: {
    // 删除全部任务
    deleteAllCheck() {
      this.deleteAll();
    },
  },
};
</script>

<style scoped>
.todo-footer {
  height: 40px;
  line-height: 40px;
  padding-left: 6px;
  margin-top: 5px;
}

.todo-footer label {
  display: inline-block;
  margin-right: 20px;
  cursor: pointer;
}

.todo-footer label input {
  position: relative;
  top: -1px;
  vertical-align: middle;
  margin-right: 5px;
}

.todo-footer button {
  float: right;
  margin-top: 5px;
}
</style>
